<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ include file="/jsp/common/common.jsp"%>  

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/common.js"/>"></script>
<script>
	function initList(listDisplayEId) {
		$('#' + listDisplayEId)
				.datagrid(
						{
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							/* frozenColumns : [ [ {
								field : 'ids',
								checkbox : true
							} ] ], */
							toolbar : [ {
								id : listDisplayEId + '_btn_edit',
								text : '确认出库材料',
								iconCls : 'icon-edit',
								handler : function() {

									var rows = $('#' + listDisplayEId)
											.datagrid('getRows');
									for (var i = 0; i < rows.length; i++) {
										var rowIndex = $('#' + listDisplayEId)
												.datagrid('getRowIndex',
														rows[i]['id']);
										$('#listDisplay').datagrid('endEdit',
												rowIndex);
									}
									var row = $('#' + listDisplayEId).datagrid(
											'getRows');
									if (row.length == 0) {
										$.messager.alert('提示', '请选择一条记录操作！',
												'info');
										return;
									} else {

										if ("${storeOutState }" !=1) {
											alert("订单状态不正确！!");
											return false;
										}

										var userList = new Array();
										var jsonFater;
										for (var i = 0; i < row.length; i++) {

											if (row[i]['materNum'] == ""
													|| !isNumberAndNoZero(row[i]['materNum'])) {
												alert("材料" + row[i]['materId']
														+ "，实际重量请填写数字！");
												return false;
											}
											var jsonSun = "{materId:'"
													+ row[i]['materId']
													+ "',id:'" + row[i]['id']
													+ "',storeOutId:'"
													+ row[i]['storeOutId']
													+ "',materDay:'"
													+ "${materDay }"
													+ "',materNum:'"
													+ row[i]['materNum']
													+ "',materValueUnit:'"
													+ row[i]['materValueUnit']
													+ "',materLevel:'"
													+ row[i]['materLevel']
													+ "'}";

											userList.push(jsonSun);
										}
										jsonFater = JSON.stringify(userList);
										var str = "json=" + jsonFater;
										document.getElementsByName("materdategridList")[0].value = jsonFater;
										$.messager.confirm('提示','是否提交记录？',function(r) {
															//方法函数 进入后台
															if(r){
																deal();
	                                                            $('#'+ listDisplayEId).datagrid('reload');
	                                                            $('#'+ listDisplayEId).datagrid('clearSelections');
															}
														});
									}
								}
							} ],
							onLoadError : function() {
								$.messager.alert('错误', '获取数据失败，请与管理员联系！',
										'error');
							},
							onClickRow : function(rowIndex) {
								$(".myrad").prop("checked", false);
								$(".myrad").eq(rowIndex).prop("checked", true);
								var row = $('#' + listDisplayEId).datagrid(
										'getRows');
								if (row[0]['storeOutWay'] != "1") {
									$('#listDisplay').datagrid('beginEdit',
											rowIndex);
								}
							}
						});
	};
	$(document).ready(function() {
		initList('listDisplay');
	});

	function deal() {
		$('#AddFoodForm').form('submit', {
			url : '<c:url value='/storeSupplier/reviewStoreOut.do'/>', //查询提交路径
			onSubmit : function()//提交按钮相应函数
			{
				return $('#AddFoodForm').form('validate');
			},
			success : function(data) {
				data = eval("(" + data + ")");
				if (data.success) {
					$.messager.alert("提示", "提交成功！", 'info', function() {
			            window.opener.window.tea();
						window.close();
					});
				} else {
					$.messager.alert("提示", data.msg, 'warning');
				}
			},
			error : function() {
				$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
				return;
			}
		});

	}

	function formatRadio(value, rowData, rowIndex) {
		return value = "<input type='radio' class='myrad'  name='radioStore' />";
	}

	function searchInfo() {

		/*  $('#listDisplay').datagrid('load', {
			storeName : $('#storeName').val(),
			storeType : $('#storeType').val()
			});  */
	}
</script>
</head>
<body>
	<form id="AddFoodForm" name="AddFoodForm" method="post">
		<table width="98%">
			<tr>
				<td>
					<table cellpadding="5">
						<tr>
							<td><input class="easyui-validatebox" type="hidden"
								name="materdategridList" /></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</form>
	<table width="98%">
		<tr>

		</tr>
		<tr style="height: 12px;"></tr>
		<tr>
			<td>
				<table id="listDisplay" title="出库详细列表" iconCls="icon-list"
					singleSelect="false" idField="id"
					url="<c:url value="/store/findStoreOutDetailed.do?storeOutId=${storeOutId}"/>"
					loadMsg="请稍候......" pagination="false" pageSize="20"
					pageList="[10,20,30,40,50]" sortName="storeOutId" rownumbers="true"
					sortOrder="asc">
					<thead>
						<tr>
							<th field="storeRole" width="25" align="center" checkbox="false">
							</th>
							<th field="id" width="80" sortable="true" editor="text"
								hidden="true">ID</th>
							<th field="storeOutId" width="80" formatter="formatDGField"
								sortable="true">出库单号</th>
							<th field="materId" width="80" formatter="formatDGField"
								sortable="true">材料id</th>
							<th field="materName" width="80" sortable="true">材料名</th>
							<th field="materType" width="50" formatter="formatFoodType1"
								sortable="true">种类</th>
							<th field="brands" width="80" sortable="true">品牌</th>
							<th field="specifications" width="120" sortable="true">规格</th>
							<th field="materNum" width="60" sortable="true" editor="text">
								数量</th>
							<th field="unit" width="60" sortable="true" editor="text">单位
							</th>
							<th field="materValueUnit" width="60" sortable="true" editor="text">单位价钱
							</th>
							<th field="materValue" width="60" sortable="true" editor="text">总价钱
                            </th>
						</tr>
					</thead>
				</table>
			</td>
		</tr>
	</table>
</body>
</html>